Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ParameterCollection.where for conditional parameter iteration #1899

Merged
merged 15 commits into from
Sep 26, 2024

Conversation

drewj-tp
Copy link
Contributor

@drewj-tp drewj-tp commented Sep 20, 2024

What is the change?

Provide ParameterCollection.where() for better iteration of parameters

Allows selective iteration of parameters that meet, by their definition
not their value, a certain condition. This would be useful to
iterate over all parameters on a Block that are relevant for
neutronics calculations with:

for p in block.p.where(lambda pd: pd.hasCategory("neutronics")):
    ...

The argument is a function that should return true for a given parameter
and can be complicated:

block.p.where(
    lambda pd: (
        pd.atLocation(ParamLocation.EDGES) or
        pd.atLocation(ParamLocation.CORNERS)
    )
)

Why is the change being made?

Inspired by HexBlock rotation where we need to do stuff for parameters that meet certain criteria.

Closes #1898


Checklist

  • The release notes have been updated if necessary.
  • The documentation is still up-to-date in the doc folder.
  • The dependencies are still up-to-date in pyproject.toml.

Allows selective iteration of parameters that meet, by their definition
not their value, meet a certain condition. This would be useful to
iterate over all parameters on a ``Block`` that are relevant for
neutronics calculations with
```python
for p in block.p.where(lambda pd: "neutronics" in pd.categories):
    ...
```
The argument is a function that should return true for a given parameter
and can be complicated
```python
block.p.where(
    lambda pd: (
        pd.atLocation(ParamLocation.EDGES) or
        pd.atLocation(ParamLocation.CORNERS)
    )
)
```

Closes #1898
(cherry picked from commit 4162cd7)
@drewj-tp drewj-tp self-assigned this Sep 20, 2024
@drewj-tp drewj-tp marked this pull request as ready for review September 21, 2024 00:01
* main:
  Fixing a problem with the latest release of h5py (#1907)
@john-science john-science added the feature request Smaller user request label Sep 25, 2024
@john-science john-science changed the title Provide ParameterCollection.where for efficient conditional iteration of parameters Adding ParameterCollection.where for conditional parameter iteration Sep 25, 2024
doc/release/0.4.rst Outdated Show resolved Hide resolved
Co-authored-by: John Stilley <[email protected]>
@john-science john-science merged commit f4223b2 into main Sep 26, 2024
19 checks passed
@john-science john-science deleted the drewj/iter-params/1898 branch September 26, 2024 16:37
drewj-tp added a commit that referenced this pull request Sep 26, 2024
…rams/1860

* origin/main:
  Adding ParameterCollection.where for conditional parameter iteration (#1899)
  Removing non-existent settings from test files (#1906)
  Removing reference to deprecated internal files (#1897)
  Fixing a problem with the latest release of h5py (#1907)
  Providing plugin hook getAxialExpansionChanger (#1870)
  Fixing typo in new settingsValidation imports (#1905)
  Startinf moving settingsValidation to the settings area (#1895)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Smaller user request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow a way to efficiently iterate over some parameters
2 participants